var Serial = require("serialport");
var port = new Serial("COM3", {
baudRate: 9600,
dataBits: 7,
stopBits: 1,
parity: 'even',
autoOpen: true
});
port.on("open", function () {
console.log('open');
});
port.on('data', function (data) {
console.log(data);
});
checksum用
function checkSum(buf) {
var cs = 0;
for (var i_1 = 1; i_1 < buf.length - 2; i_1++)
cs += buf[i_1];
var rr = (cs & 0xFF).toString(16);
return "0".repeat(2 - rr.length) + rr;
}